import {
  AddressPayload,
  ApiItemTypeMapping,
  EventRecommendationShape,
} from "@/data/shared/entityShapes";
import { CourseSchedulingShape } from "../courses/courseTypes";
import { DateShape, DateTimeShape, TimeShape } from "../shared/timeTypes";
import { ApiTalkTypes } from "../talks/talkTypes";

export type PreOrderType = "shoppingCart" | "buyNow" | "again";

export type OrderShape = {
  preOrderCommonVo: {
    preOrderNo: string;
    cartIdList?: number[];
    count: number;
    type: ApiItemTypeMapping;
    preOrderType: PreOrderType;
    totalPrice: string;
    totalPriceCourse?: string;
    totalPriceShop?: string;

    eventInfoDetail?: {
      name: string;
      mainId: number;
      buyCount: number;
      price: number;
      coverImage: string;
      endTime: DateShape;
      startTime: DateShape;
      typeLabelColor: string;
      typeName: string;
      schedulings: Array<
        CourseSchedulingShape & { courseAddress: AddressPayload }
      >;
      talkType?: number;
    };

    productDetail?: {
      name: string;
      price: string;
      primaryKey: number;
      productId: number;
      refundStatus: number;
      sku: "default" | Omit<string, "default">;
      attrValueId: number;
      buyNum: number;
      cardNo: number;
      endTime: DateShape;
      faceValue: number;
      image: string;
      introduction: number;
      isbnCode: number;
      labelColor: number;
      type: number;
      useAround: number; //0=课程 1=讲座 2=展览
      useType: number; //1=分类卡 2=课程卡/讲座卡/展览卡
      volume: number;
      weight: number;
    }[];
  };
  publicationRecommendations: EventRecommendationShape[];
};

export enum ApiCourseTypes {
  Single = 0,
  Discovery = 1,
}

export enum ApiRefundStatus {
  NotRefunded = 0,
  InApplication = 1,
  Refunded = 2,
  BeingRefunded = 3,
  ToBeReturned = 4,
  BeingReturned = 5,
  RefundCancelled = 6,
}

export enum ApiOrderStatus {
  NotShipped = 0,
  ToBeRecieved = 1,
  CompletedNotYetEval = 2,
  CompletedAndEvaluated = 3,
}

export enum ApiIsGiftCard {
  No = 0,
  Yes = 1,
}

// Removed fields not used in User-Order-Detail-Page
export type OrderDetailShape = {
  id: number;
  orderNo: string;
  mainId: number | null;
  orderStatus: string;
  couponPrice: string | null;
  type: ApiItemTypeMapping;
  productId: number | null;
  liveLink: string;
  paid: boolean;
  isDel: boolean;
  unpaidCountdown: null | number;
  refundStatus: ApiRefundStatus;
  status: ApiOrderStatus;
  isGiftCard: null | ApiIsGiftCard;
  talkType: null | ApiTalkTypes;
  lecturerName: string; // Unclear if can be null
  lecturerPhone: string; // Unclear if can be null
  proTotalPrice: string; // Unclear if can be null
  payPrice: number;
  userAddress: null | string;
  realName: string;
  userPhone: string;
  totalPrice: string;
  createTime: DateTimeShape;
  isAfterSalesTime: boolean;
  payTime: DateTimeShape;
  deliveryName: null | string;
  masterWaybillNo: null | string;
  preOrderProductDetails: {
    attrValueId: number;
    buyNum: number;
    cardNo: string;
    endTime: number;
    faceValue: number;
    image: string;
    introduction: string;
    isbnCode: string;
    labelColor: string;
    name: string;
    orderInfoStatus: string;
    payPrice: number;
    price: number;
    primaryKey: string;
    productId: number;
    refundStatus: number;
    sku: "default" | Omit<string, "default">;
    type: string;
    useAround: number;
    useType: number;
    volume: number;
    weight: number;
  }[];
  courseInfoDetails: {
    name: string;
    typeName: string;
    typeLabelColor: string;
    schedulings: {
      courseId: number;
      scheduleId: number;
      schedulingDate: DateShape;
      schedulingStartTime: TimeShape;
      schedulingEndTime: TimeShape;
      language: string;
      courseAddress: {
        courseAddress: string;
        courseAddressInfo: string;
        dest: string;
        lat: string;
        lon: string;
      };
    }[];
    talkType: ApiTalkTypes;
  };
  routes: null | {
    acceptAddress: string;
    acceptTime: string;
    opcode: string;
    remark: string;
  };
};

export type CheckoutModalShape = {
  eventList?: {
    name: string;
    date: string;
    time: string;
  }[];
  participantList?: {
    name: string;
    phoneNumber: string;
  }[];
  submitHandler?: () => void;
};

export type OrderPaymentStatusResponseShape = {
  msg: string;
  payFree: number;
  status: boolean;
};
